<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input class="ipt1" type="text" />
    <input class="ipt2" type="text" />
    <button>点我</button>
    <input class="ipt3" type="text" />
  </body>
</html>
<script>
  //获取元素
  var oIpt1 = document.querySelector(".ipt1");
  var oIpt2 = document.querySelector(".ipt2");
  var oBtn = document.querySelector("button");
  var oIpt3 = document.querySelector(".ipt3");
  var count = 0;
  oBtn.onclick = function () {
    if (oIpt1.value.trim() == "" || oIpt2.value.trim() == "")
      return alert("请输入内容"); //判断是否为空
    if (isNaN(oIpt1.value) || isNaN(oIpt2.value)) return alert("请输入数字"); //判断是否为非数字
    if (oIpt1.value > oIpt2.value)
      return alert("第一个输入框的数字大于第二个输入框的数字"); // 判断输入框数字是否规范
    for (var i = oIpt1.value; i <= oIpt2.value; i++) {
      var a = i % 10;
      var b = parseInt(i / 10) % 10;
      var c = parseInt(i / 100);

      if (i == a ** 3 + b ** 3 + c ** 3) {
        count++;
      }
    }
    oIpt3.value = count;
  };
</script>
